<template>
  <div class></div>
</template>
<script>
import axios from "@/utils/requestdp";

export default {
  name: "APIqueryDbPipenetzz",
  components: {},
  data() {
    return {};
  },
  computed: {
    ishistory: function() {
      return this.$store.state.daping.ishistorytime;
    },
    timerangarr: function() {
      return this.$store.state.daping.timepick;
    }
  },
  watch: {},
  mounted() {
    this.watchEvent();
  },
  methods: {
    watchEvent() {
      //先清除定时任务
      if (
        this.$store.state.daping.intervalArr["APIqueryDbPipenetzz"] != undefined
      ) {
        clearInterval(
          this.$store.state.daping.intervalArr["APIqueryDbPipenetzz"][0].interval
        );
      }
      this.loadData();
      let interval = setInterval(() => {
        this.loadData();
      }, this.$root.setting.data.interval);
      this.$store.state.daping.intervalArr["APIqueryDbPipenetzz"] = [
        { interval: interval }
      ];
    },
    loadData() {
      axios.get('/bigScreen/bigScreen').then(res => {
        let rs = res.data.filter(v => v.attrName === 'network_ids')[0].attrValue.split(',');
        let ids = [];
        let names = [];
        rs.forEach(r => {
          ids.push(r.split('@@')[1])
          names.push(r.split('@@')[2])
        })
        let queryArr = [];
        ids.forEach(v => {
          queryArr.push(axios.get(`/manage/networkMonitor?pageNum=1&pageSize=30&sourceType=${v}&sort=`))
        })
        let pipenetDataObj = [];
        Promise.all(queryArr).then(res => {
          res.forEach((r, index) => {
            if (r.code == 200) {
              pipenetDataObj.push({
                [names[index]]: r.data[0]
              })
            }
          })
          this.$store.state.daping.queryDbPipenetzz = pipenetDataObj;
        })
      })
    }
  }
};
</script>
<style lang='scss' scoped>
</style>